package com.rules.admin.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.rules.admin.entity.HolidaysModel;
import com.rules.admin.service.HolidaysService;
import com.rules.admin.utils.ResultUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RequestMapping({"/holidays"})
@Controller
public class HolidaysController {
   @Autowired
   private HolidaysService holidaysService;

   @RequestMapping(
      method = {RequestMethod.GET}
   )
   @ResponseBody
   public IPage<HolidaysModel> queryPage(IPage<HolidaysModel> page, HolidaysModel holidaysModel) {
      return this.holidaysService.queryPage(holidaysModel.getHoliday(), page);
   }

   @RequestMapping(
      value = {"/{id}"},
      method = {RequestMethod.GET}
   )
   @ResponseBody
   public HolidaysModel getRule(@PathVariable("id") Long id) {
      return (HolidaysModel)this.holidaysService.getById(id);
   }

   @RequestMapping(
      method = {RequestMethod.POST}
   )
   @ResponseBody
   public Map<String, Object> addDataDict(@RequestBody HolidaysModel holidaysModel) {
      this.holidaysService.save(holidaysModel);
      return ResultUtils.getSuccessResultData();
   }

   @RequestMapping(
      value = {"/{id}"},
      method = {RequestMethod.DELETE}
   )
   @ResponseBody
   public Map<String, Object> deleteDataDict(@PathVariable("id") Long id) {
      this.holidaysService.removeById(id);
      return ResultUtils.getSuccessResultData();
   }

   @RequestMapping(
      value = {"/getAll"},
      method = {RequestMethod.POST}
   )
   @ResponseBody
   public List<HolidaysModel> getAll() {
      return this.holidaysService.selectAll();
   }

   @RequestMapping({"/publish"})
   @ResponseBody
   public Map<String, Object> publish() {
      this.holidaysService.publish();
      return ResultUtils.getSuccessResultData();
   }
}
